<template>
	<view class="page-container">
		<view class="main-content">
			<!-- 报销人基本信息 -->
			<view class="section-box mb-20">
				<view class="section-title">
					<u-icon name="account" color="#1E40AF" size="24" class="icon-mr"></u-icon>
					<text class="title-text">报销信息</text>
				</view>
				<view class="detail-cell">
					<view class="label">实际报销人名称:</view>
					<view class="value">{{detailData.payerPartyName}}</view>
				</view>
				<view class="detail-cell">
					<view class="label">实际报销人代码:</view>
					<view class="value">{{detailData.payerPartyCode}}</view>
				</view>
				<view class="detail-cell">
					<view class="label">授权时间:</view>
					<view class="value">{{ formatDate(detailData.authorizeDate)}} {{detailData.authorizeTime}}</view>
				</view>
				<view class="detail-cell">
					<view class="label">授权记录状态:</view>
					<view class="value">
						{{ detailData.resultCode == '02' ? '已确认' : (detailData.resultCode == '01' ? '待确认' : (detailData.resultCode == '03' ? '已拒收' : (detailData.resultCode == '04' ? '已撤销' : '')))}}
					</view>
				</view>
			</view>

			<!-- 报销事由 -->
			<view class="section-box mb-20">
				<view class="section-title">
					<u-icon name="file-text" color="#1E40AF" size="24" class="icon-mr"></u-icon>
					<text class="title-text">报销事由</text>
				</view>
				<u--textarea v-model="detailData.authorizeRemark" disabled placeholder="请详细描述报销事由"></u--textarea>
			</view>

			<!-- 财政票据列表 -->
			<view class="section-box">
				<view class="section-title">
					<u-icon name="order" color="#1E40AF" size="24" class="icon-mr"></u-icon>
					<text class="title-text">财政票据列表</text>
				</view>

				<!-- 票据列表 -->
				<view class="receipt-list">
					<!-- 循环票2 -->
					<scroll-view style="height: 450rpx;"
						scroll-y :scroll-with-animation="true">
						<view class="receipt-item" v-for="(item,index) in detailData.eInvoiceList" :key="index" @click="goBillDetail(item)">
							<view class="receipt-info">
								<view class="info-row">
									<text class="info-label">票据号码：</text>
									<text class="info-value">{{item.eInvoiceNumber}}</text>
									<text class="receipt-amount">¥ {{(item.totalAmount).toFixed(2)}}</text>
								</view>
								<view class="info-row">
									<text class="info-label">票据代码：</text>
									<text class="info-value">{{item.eInvoiceCode}}</text>
								</view>
								<view class="info-row">
									<text class="info-label">校 验 码：</text>
									<text class="info-value">{{item.randomNumber}}</text>
								</view>
								<view class="info-row">
									<text class="info-label">开票日期：</text>
									<text class="info-value">{{item.issueDate}}</text>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailData: {
					eInvoiceList: []
				},
				formData: {
					userName: '',
					identityCardNo: '',
				},
				selectedBills: [],
				reason: '',
				selectedUnit: {},
				showReceiptModal: false,
				receiptForm: {
					type: '',
					number: '',
					amount: '',
					date: '',
					unit: ''
				},
			};
		},
		onLoad: function(option) {
			if (option && option.item) { //手工查票跳转
				this.detailData = JSON.parse(decodeURIComponent(option.item))
				console.log('detail', this.detailData)
			}
		},
		computed: {},
		methods: {
			formatDate(str) {
				console.log('===', str)
				// 检查输入格式是否正确（8位数字）
				if (!/^\d{8}$/.test(str)) {
					return
				}
				// 提取年、月、日
				const year = str.substring(0, 4);
				const month = str.substring(4, 6);
				const day = str.substring(6, 8);
				// 拼接成目标格式
				return `${year}-${month}-${day}`;
			},
			navigateBack() {
				uni.navigateBack();
			},
			goBillDetail(item){
				console.log('item',item)
				const params={
					...item,
					einvoiceCode:item.eInvoiceCode,
					einvoiceNumber:item.eInvoiceNumber,
				}
				// 跳转到票据详情页
				uni.navigateTo({
					url: '/pages/home/billdetail?item=' + encodeURIComponent(JSON.stringify(params))
				})
			},
		}
	};
</script>

<style scoped>
	.page-container {
		background-color: #f5f5f5;
		min-height: 100vh;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
	}

	.main-content {
		padding: 32rpx;
	}

	.section-box {
		background-color: #ffffff;
		border-radius: 24rpx;
		padding: 32rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
	}

	.section-title {
		display: flex;
		align-items: center;
		margin-bottom: 32rpx;
		font-weight: 600;
		color: #333333;
	}

	.detail-cell {
		display: flex;
		align-items: center;
		color: #303133;
		font-size: 28rpx;
		padding: 10rpx 0;
	}

	.label {
		width: 240rpx;
		text-align: end;
		padding-right: 40rpx;
	}

	.icon-mr {
		margin-right: 16rpx;
	}

	.title-text {
		font-size: 32rpx;
	}

	.form-grid {
		display: grid;
		grid-template-columns: 1fr;
		gap: 32rpx;
	}

	.form-item {
		display: flex;
		align-items: center;
		padding-bottom: 32rpx;
		border-bottom: 2rpx solid #f2f2f2;
		position: relative;
	}

	.form-item:last-child {
		border-bottom: none;
	}

	.form-label {
		width: 160rpx;
		font-size: 28rpx;
		color: #666666;
	}

	.form-input {
		flex: 1;
		font-size: 28rpx;
		padding: 0;
		height: 72rpx;
	}

	.select-arrow {
		position: absolute;
		right: 0;
	}

	.reason-input {
		width: 100%;
		padding: 20rpx;
		background-color: #f9f9f9;
		border-radius: 16rpx;
		font-size: 28rpx;
	}

	.word-count {
		display: block;
		text-align: right;
		font-size: 24rpx;
		color: #999999;
		margin-top: 16rpx;
	}

	.receipt-list {
		margin-bottom: 40rpx;
	}

	.receipt-item {
		border: 2rpx solid #f2f2f2;
		border-radius: 16rpx;
		padding: 32rpx;
		margin-bottom: 32rpx;
		position: relative;
		transition: all 0.3s;
	}

	.receipt-item-hover {
		box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
	}

	.delete-icon {
		position: absolute;
		top: 5rpx;
		right: 10rpx;
	}

	.receipt-info {
		/* padding-right: 48rpx; */
		padding-top: 30rpx;
	}

	.info-row {
		display: flex;
		margin-bottom: 20rpx;
		font-size: 28rpx;
	}

	.info-row:last-child {
		margin-bottom: 0;
	}

	.info-label {
		display: inline-block;
		width: 120rpx;
		color: #666666;
		margin-right: 16rpx;
		white-space: nowrap;
	}

	.info-value {
		color: #333333;
		flex: 1;
	}

	.receipt-amount {
		color: #1E40AF;
		font-weight: 600;
	}

	.add-receipt-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		padding: 24rpx 0;
		border: 4rpx dashed #e0e0e0;
		border-radius: 16rpx;
		color: #999999;
		font-size: 28rpx;
		transition: all 0.3s;
	}

	.add-receipt-btn:hover {
		border-color: #1E40AF;
		color: #1E40AF;
	}

	.bottom-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: #ffffff;
		border-top: 2rpx solid #f2f2f2;
		padding: 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
	}

	.total-amount {
		display: flex;
		align-items: center;
	}

	.total-label {
		font-size: 28rpx;
		color: #666666;
		margin-right: 16rpx;
	}

	.total-value {
		font-size: 36rpx;
		font-weight: 600;
		color: #1E40AF;
	}

	.submit-btn {
		width: 200rpx;
		height: 88rpx;
		border-radius: 16rpx;
		font-size: 32rpx;
	}


	.receipt-modal {
		padding: 40rpx;
	}

	.modal-content {
		display: flex;
		flex-direction: column;
	}

	.modal-title {
		font-size: 36rpx;
		font-weight: 600;
		margin-bottom: 40rpx;
		color: #333333;
	}

	.upload-area {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx;
		border: 4rpx dashed #e0e0e0;
		border-radius: 16rpx;
	}

	.upload-icon {
		margin-bottom: 20rpx;
	}

	.upload-text {
		font-size: 28rpx;
		color: #999999;
		margin-bottom: 10rpx;
	}

	.upload-hint {
		font-size: 24rpx;
		color: #cccccc;
	}

	.confirm-btn {
		width: 100%;
		height: 88rpx;
		background-color: #1E40AF;
		color: #ffffff;
		border-radius: 16rpx;
		margin-top: 40rpx;
	}

	/* 间距类 */
	.mb-20 {
		margin-bottom: 40rpx;
	}

	.mb-160 {
		margin-bottom: 320rpx;
	}
</style>